package org.example.bookstore.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.example.bookstore.custom.ResultVO;
import org.example.bookstore.pojo.DO.Order;
import org.example.bookstore.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "订单Api")
@RestController
@CrossOrigin
@Slf4j
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /*
     * 生成订单
     * */
    @Operation(summary = "生成订单")
    @PutMapping("/add")
    public ResultVO<?> addOrder(@RequestBody Order order){
        return orderService.addOrder(order);
    }
    /*
     * 的订单查询  根据用户id查询所有订单信息
     * */
    @Operation(summary = "查询订单列表")
    @GetMapping("/list")
    public ResultVO<?> selectOrderList(@Parameter(name = "id", description = "用户id") @RequestParam Integer id){
        return orderService.getOrderList(id);
    }
        /*
         * 根据评论id删除订单
         * */
    @Operation(summary = "删除订单")
    @DeleteMapping("/delete")
    public ResultVO<?> deleteOrder(@Parameter(name = "id", description = "订单id") @RequestParam Integer id){
        return orderService.deleteOrder(id);
    }
}
